package com.twu.biblioteca;

import java.util.LinkedHashMap;
import java.util.Map;

public class SessionManager {
    private Map<String, User> userMap;
    private User authenticatedUser;

    public SessionManager() {
        userMap = new LinkedHashMap<String, User>();
    }
    public void addUser(User user) {
        userMap.put(user.displayUsername(), user);
    }

    public void loginUser(String username, String password) {
        User user = userMap.get(username);
        if(user != null && user.passwordEquals(password)) {
            authenticatedUser = user;
        } else {
            authenticatedUser = null;
        }
    }

    public boolean isAuthenticated() {
        return authenticatedUser != null;
    }

    public String displayUserDetails() {
        if(isAuthenticated()) {
            return authenticatedUser.displayUserDetails();
        }
        return "Please login";
    }
}